package com.lcy.demo;

import com.alibaba.dubbo.rpc.protocol.rest.support.ContentType;

import javax.ws.rs.*;
import javax.ws.rs.core.MediaType;
import java.util.Arrays;
import java.util.List;

/**
 * <p>创建时间：2017/4/17 10:55</p>
 *
 * @author 娄存银
 * @version 1.0
 */
@Path("test")
@Consumes({MediaType.APPLICATION_JSON, MediaType.TEXT_XML})
@Produces({ContentType.APPLICATION_JSON_UTF_8, ContentType.TEXT_XML_UTF_8})
public class TestServiceImpl implements TestService{
    @Override
    @GET
    @Path("list")
    public List<String> list(@QueryParam("col") String[] strings) {
        return Arrays.asList(strings);
    }

    @Override
    @POST
    @GET
    @Path("obj")
    public Object getObject( User user) {
        System.out.println(user);
        return user;
    }

    @Override
    @GET
    @Path("num")
    public Object getNumber(@QueryParam("col") String[] strings) {
        return strings.length;
    }

    @Override
    @GET
    @Path("exception")
    public Object exception() throws CustomException {
        if(true){
            throw new CustomException(2,"test exception handle");
        }
        return 1;
    }


}
